package com.heima.wemedia;

import com.heima.file.service.FileStorageService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;

import java.io.FileInputStream;
import java.io.FileNotFoundException;

@SpringBootTest
public class testOss {
    @Autowired
    private FileStorageService fileStorageService;
    @Value("${file.oss.prefix}") //直接从配置中动态读取
    String prefix;
    @Value("${file.oss.web-site}") //直接从配置中动态读取
    String webSite;
    @Test
    public void store() throws FileNotFoundException {
        //参数一上传的文件夹
        //参数二 文件在文件夹的名称
        //参数三 要输入流
        FileInputStream inputStream = new FileInputStream("D:\\痕迹想法\\桌面壁纸\\015.jpg");
        //获得的是文件在oss中的完整路径
        String store = fileStorageService.store(prefix, "beauty02.jpg", inputStream);
        //图片访问前缀 + oss 中的完整路径
        System.out.println(webSite +"/"+ store);
        //https://leadnews-sh.oss-cn-shanghai.aliyuncs.com/material/2022/7/20220728/beauty02.jpg
        //http://leadnews-sh.oss-cn-shanghai.aliyuncs.com/material/2022/7/20220728/beauty02.jpg
    }
    @Test
    public void delete() throws FileNotFoundException {
         fileStorageService.delete("03.jpg");
    }
}
